
package jfc.util;

import java.awt.Point;
import jfc.core.CardGroup;
import jfc.ui.MainWindow;

/**
 *  @author Yann Le Gall
 *  ylegall@gmail.com
 *  Oct 27, 2009 11:16:55 PM
 */
public class Animator
{
    private CardGroup cardGroup;
    private MainWindow window;

    public Animator(MainWindow window, CardGroup cardGroup) {
        this.cardGroup = cardGroup;
        this.window = window;
    }

    public void animate(Point end)
    {
        Point start = cardGroup.getLocation();
        window.setPanelImage();

        double dx = ((end.x - start.x)/5050d);
        double dy = ((end.y - start.y)/5050d);
        double totalX = start.x;
        double totalY = start.y;

        for(int i=100; i > 0; i--) {
            start.x =  (int)totalX;
            start.y = (int)totalY;
            cardGroup.setLocation(start);
            totalX += i*dx;
            totalY += i*dy;
            
            try { Thread.sleep(3); }
            catch (InterruptedException e) {}

            window.paintPanel();
        }
    }
}
